﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;

namespace Lin.Website.Admin
{
    //wait(30000) 超时时间30秒
    public class BaseApi
    {
        public static HttpResponseMessage Get(string url)
        {
            HttpResponseMessage response = null;

            new HttpClient().GetAsync(url).ContinueWith(requestTask =>
            {
                response = requestTask.Result;

            }).Wait(30000);

            return response;
        }

        public static string Post(string url, string param = "")
        {

            var json = string.Empty;
            var httpContent = new StringContent(param);


            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            new HttpClient().PostAsync(url, httpContent).ContinueWith(requestTask =>
            {
                if (requestTask.Result.IsSuccessStatusCode)
                {
                    json = requestTask.Result.Content.ReadAsStringAsync().Result;
                }

            }).Wait(30000);

            return json;
        }
    }
}